package logic

import (
	"context"
	"zye6/user_srv/user"

	"zye6/api/internal/svc"
	"zye6/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddPositionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddPositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPositionLogic {
	return &AddPositionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddPositionLogic) AddPosition(req *types.AddPositionRequest) (resp *types.RegMsgResponse, err error) {
	// todo: 发布职位

	if req.Address == "" || req.PositionleiBie == "" {
		return &types.RegMsgResponse{
			Cre:  -1,
			Msg:  "职位类型，工作地址不能为空",
			Data: nil,
		}, nil
	}

	_, err = l.svcCtx.UserSrv.AddPosition(l.ctx, &user.AddPositionRequest{
		PositionName:   req.PositionName,
		PositionLeiBie: req.PositionleiBie,
		Address:        req.Address,
		Price:          float32(req.Price),
		Work:           req.Work,
	})
	if err != nil {
		return &types.RegMsgResponse{
			Cre:  -1,
			Msg:  "服务器错误",
			Data: nil,
		}, err
	}

	return &types.RegMsgResponse{
		Cre:  0,
		Msg:  "发布成功",
		Data: nil,
	}, err
}
